package com.itheima02;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;

public class Test06 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        HashMap<String,Object>map=new HashMap<>();
        map.put("id","heima001");
        map.put("name","张三");
        map.put("age",23);
        map.put("birthday","1999-09-09");


        Class clazz = Class.forName("com.itheima02.Student02");

        Student02 stu = (Student02) clazz.getDeclaredConstructor().newInstance();

        Method[] methods = clazz.getMethods();

        for (String key : map.keySet()) {
            Object value = map.get(key);
            for (Method m : methods) {
                if("set".concat(key.substring(0,1).toUpperCase().concat(key.substring(1))).equals(m.getName())){

                    m.invoke(stu,value);

                }
            }
        }

        System.out.println(stu);
    }
}
